﻿<%@ Page Language="C#" MasterPageFile="~/default.Master" AutoEventWireup="true" CodeBehind="BookDetail.aspx.cs"
    Inherits="BookNet.WebForm4" Title="Book Detail" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style3
        {
            width: 100%;
            border: 0;
        }
        .style4
        {
            width: 115px;
            vertical-align: top;
            border: 0;
        }
        .style6
        {
            height: 24px;
            border: 0;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <p>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                    SelectCommand="SELECT app_Books.BookID, app_Books.Seller, app_Books.Title, app_Books.Description, app_Books.Price, app_Books.TimeAdded, app_Books.CoverImageUrl, app_Books.ForLending, app_Books.Condition, app_Books.ISBN, app_Books.Author, aspnet_Users.UserId, aspnet_Users.UserName FROM app_Books INNER JOIN aspnet_Users ON app_Books.Seller = aspnet_Users.UserId WHERE (app_Books.BookID = @BookID)"
                    OnSelecting="SqlDataSource2_Selecting">
                    <SelectParameters>
                        <asp:Parameter Name="BookID" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <br />
                <br />
                <h3>
                    Book Detail</h3>
                <br />
                <asp:FormView ID="FormView2" runat="server" DataKeyNames="BookID" DataSourceID="SqlDataSource2">
                    <ItemTemplate>
                        <table align="left" class="style3" width="100%">
                            <tr>
                                <td class="style4">
                                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# ChooseImage(Eval("CoverImageUrl").ToString()) %>' />
                                </td>
                                <td style="padding-left: 10px; width: 500px;">
                                    <table class="table_footer" width="100%" border="0px">
                                        <tr>
                                            <td colspan="2">
                                                <strong><em>
                                                    <asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' Font-Size="Large" /></strong></em>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="left">
                                                <asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>' ForeColor="Red"
                                                    Font-Size="Large" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <hr />
                                                ISBN:
                                                <asp:Label ID="ISBNLabel" runat="server" Text='<%# Bind("ISBN") %>' />
                                            </td>
                                            <td>
                                                Seller: <a href="UserDetail.aspx?id=<%# Eval("UserID") %>">
                                                    <asp:Label ID="SellerLabel" runat="server" Text='<%# Bind("Username") %>' /></a>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="AuthorLabel" runat="server" Text='<%# Bind("Author") %>' />
                                            </td>
                                            <td>
                                                Lending:<asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Bind("ForLending") %>'
                                                    Enabled="false" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Time added:
                                                <asp:Label ID="TimeAddedLabel" runat="server" Text='<%# Bind("TimeAdded") %>' />
                                            </td>
                                            <td>
                                                Condition:
                                                <asp:Label ID="ConditionLabel" runat="server" Text='<%# Bind("Condition") %>' />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    &nbsp;
                                </td>
                            </tr>
                        </table>
                        <br />
                        <hr />
                    </ItemTemplate>
                </asp:FormView>
                <p>
                </p>
                <hr />
                <h5>
                    Comments</h5>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>" 
                    DeleteCommand="DELETE FROM [app_Comments] WHERE [ID] = @ID" 
                    InsertCommand="INSERT INTO [app_Comments] ([ID], [ObjectID], [Rating], [Comment], [TimeAdded]) VALUES (@ID, @ObjectID, @Rating, @Comment, @TimeAdded)" 
                    OnSelecting="SqlDataSource1_Selecting" 
                    SelectCommand="SELECT * FROM [app_Comments] WHERE ([ObjectID] = @ObjectID) ORDER BY [TimeAdded] DESC" 
                    UpdateCommand="UPDATE [app_Comments] SET [ObjectID] = @ObjectID, [Rating] = @Rating, [Comment] = @Comment, [TimeAdded] = @TimeAdded WHERE [ID] = @ID">
                    <SelectParameters>
                        <asp:Parameter Name="ObjectID" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="ID" Type="Object" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="ObjectID" Type="Object" />
                        <asp:Parameter Name="Rating" Type="Int32" />
                        <asp:Parameter Name="Comment" Type="String" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                        <asp:Parameter Name="ID" Type="Object" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ID" Type="Object" />
                        <asp:Parameter Name="ObjectID" Type="Object" />
                        <asp:Parameter Name="Rating" Type="Int32" />
                        <asp:Parameter Name="Comment" Type="String" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    </InsertParameters>
                </asp:SqlDataSource>
                <asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" 
                    DataSourceID="SqlDataSource1">
                    <ItemTemplate>
                        <table width="700">
                            <tr>
                                <td style="width: 115px; vertical-align: top;">
                                    <asp:Image ID="Image1" runat="server" ImageUrl="images/anonymous.gif" 
                                        Width="100" />
                                </td>
                                <td style="width: 585px; vertical-align: top; padding-top: 10px;">
                                    <table width="100%">
                                        <tr>
                                            <td align="left">
                                                Rating:
                                                <cc1:Rating ID="Rating2" runat="server" CurrentRating='<%# Eval("Rating") %>' 
                                                    EmptyStarCssClass="emptyRatingStar" FilledStarCssClass="filledRatingStar" 
                                                    MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" 
                                                    WaitingStarCssClass="savedRatingStar">
                                                </cc1:Rating>
                                            </td>
                                            <td align="right">
                                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                    <br />
                                    Comment:
                                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                        <table style="background-color: #CCFFCC;" width="700">
                            <tr>
                                <td style="width: 115px; vertical-align: top;">
                                    <asp:Image ID="Image1" runat="server" ImageUrl="images/anonymous.gif" 
                                        Width="100" />
                                </td>
                                <td style="width: 585px; vertical-align: top; padding-top: 10px;">
                                    <table width="100%">
                                        <tr>
                                            <td>
                                                Rating:
                                                <cc1:Rating ID="Rating2" runat="server" CurrentRating='<%# Eval("Rating") %>' 
                                                    EmptyStarCssClass="emptyRatingStar" FilledStarCssClass="filledRatingStar" 
                                                    MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" 
                                                    WaitingStarCssClass="savedRatingStar">
                                                </cc1:Rating>
                                            </td>
                                            <td align="right">
                                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                    <br />
                                    Comment:
                                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </AlternatingItemTemplate>
                    <EmptyDataTemplate>
                        No data was returned.
                    </EmptyDataTemplate>
                    <LayoutTemplate>
                        <div style="text-align: left; background-color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif;
                        color: #000000; width: 700px; padding-left: 0px;">
                            <table ID="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;
                            list-style-type: none; width: 600px; padding-left: 0px;">
                                <tr style="background-color: #000000; color: #000000; list-style-type: none; padding-left: 0px;">
                                    <td ID="itemPlaceholder" runat="server">
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div style="text-align: left; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                        color: #000000; width: 700px;">
                            <asp:DataPager ID="DataPager1" runat="server" PageSize="5">
                                <Fields>
                                    <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" 
                                        ShowLastPageButton="True" />
                                </Fields>
                            </asp:DataPager>
                        </div>
                    </LayoutTemplate>
                    <ItemSeparatorTemplate>
                    </ItemSeparatorTemplate>
                </asp:ListView>
                <br />
                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>" 
                    DeleteCommand="DELETE FROM [app_Comments] WHERE [ID] = @ID" 
                    InsertCommand="INSERT INTO [app_Comments] ([ObjectID], [Rating], [Comment], [TimeAdded]) VALUES (@ObjectID, @Rating, @Comment, @TimeAdded)" 
                    oninserted="SqlDataSource3_Inserted" OnInserting="SqlDataSource3_Inserting" 
                    SelectCommand="SELECT * FROM [app_Comments]" 
                    UpdateCommand="UPDATE [app_Comments] SET [ObjectID] = @ObjectID, [Rating] = @Rating, [Comment] = @Comment, [TimeAdded] = @TimeAdded WHERE [ID] = @ID">
                    <DeleteParameters>
                        <asp:Parameter Name="ID" Type="Object" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="ObjectID" Type="Object" />
                        <asp:Parameter Name="Rating" Type="Int32" />
                        <asp:Parameter Name="Comment" Type="String" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                        <asp:Parameter Name="ID" Type="Object" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ObjectID" />
                        <asp:Parameter Name="Rating" Type="Int32" />
                        <asp:Parameter Name="Comment" Type="String" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    </InsertParameters>
                </asp:SqlDataSource>
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                    DataKeyNames="ID" DataSourceID="SqlDataSource3" DefaultMode="Insert" 
                    Height="50px" Width="125px">
                    <Fields>
                        <asp:TemplateField HeaderText="Rating" SortExpression="Rating">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rating") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <cc1:Rating ID="Rating1" runat="server" CurrentRating="3" 
                                    EmptyStarCssClass="emptyRatingStar" FilledStarCssClass="filledRatingStar" 
                                    MaxRating="5" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar">
                                </cc1:Rating>
                                <br />
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Rating") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Comment" SortExpression="Comment">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Comment") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Height="100px" 
                                    Text='<%# Bind("Comment") %>' TextMode="MultiLine" Width="615px"></asp:TextBox>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <InsertItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                    CommandName="Insert" Text="Add Comment"></asp:LinkButton>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                    CommandName="New" Text="New"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Fields>
                </asp:DetailsView>
            </p>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
